module.exports = function($scope, $resource, $modal, $modalInstance, place, activities, toaster){


	$scope.activities = activities;
	$scope.activities.forEach(function(value, index, array){
		if(place.activities && place.activities.indexOf(value.value) != -1){
			value.check = true;
		} else {
			value.check = false;
		}
	});
	

	$scope.gogo = function(){
		var para = {'place_id': place.id }, list = [];
		angular.forEach($scope.activities, function(item){
			if(item.check){
				list.push(item.value);
			}
		});
		para.activities = list.toString() || null;
		
		$resource('/api/as/tc/place/updatePlaceAct', {}, {}).save(para, function(res) {
			if (res.errcode === 0) {
				toaster.success({title: '', body: '成功'});
				$modalInstance.close(para.activities);
            } else {
                toaster.error({title: '', body: '失败'});
            }
        });
	};

	$scope.close = function(){
		$modalInstance.dismiss('cancel');
	}

};
